package com.gxa.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.mapper.CustomerCareWarnMapper;
import com.gxa.param.MyTableParam;
import com.gxa.pojo.Warn;
import com.gxa.service.CustomerCareWarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Throwable.class)
public class CustomerCareWarnServiceImpl implements CustomerCareWarnService {
    @Autowired
    private CustomerCareWarnMapper customerCareWarnMapper;

    @Override
    public LayR list(MyTableParam param) {

        PageHelper.startPage(param.getPage(),param.getLimit());

        List<Warn> warns = customerCareWarnMapper.findAll(param);

        PageInfo<Warn> warnPageInfo = new PageInfo<>(warns);

        return new LayR(0,"success",warnPageInfo.getList(),warnPageInfo.getTotal());
    }

    @Override
    public LayR updatestatus(Warn warn) {

        customerCareWarnMapper.update(warn);
        return new LayR(200,"success");
    }

    @Override
    public R add(Warn warn) {
        customerCareWarnMapper.save(warn);
        return new R(200,"添加成功");
    }

    @Override
    public R edit(Warn warn) {
        customerCareWarnMapper.update(warn);
        return new R(200,"修改成功");
    }

    @Override
    public R deleteAll(String[] ids) {

        customerCareWarnMapper.deleteAll(ids);
        return new R(200,"删除成功");
    }

    @Override
    public R deleteOne(Integer warnId) {
        customerCareWarnMapper.deleteOneById(warnId);
        return new R(200,"删除成功");
    }

    @Override
    public R findById(Integer warnId) {
        Warn byPk = customerCareWarnMapper.findByPk(warnId);

        return new R(200,"success",byPk);
    }

}
